﻿// ----------------------------------------------------------------------------------
// Microsoft Developer & Platform Evangelism
// 
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// ----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// MenuEntry.cs
//
// XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Graphics;

namespace EngineGame
{
    /// <summary>
    /// Helper class represents a single entry in a MenuScreen. By default this
    /// just draws the entry text string, but it can be customized to display menu
    /// entries in different ways. This also provides an event that will be raised
    /// when the menu entry is selected.
    /// </summary>
    class MenuEntry
    {
        /// <summary>
        /// The text rendered for this entry.
        /// </summary>
        public string text;
        public Vector2 position;
        public Rectangle EntryPosition { get; set; }
        public bool isTouch;
        /// <summary>
        /// Tracks a fading selection effect on the entry.
        /// </summary>
        /// <remarks>
        /// The entries transition out of the selection effect when they are deselected.
        /// </remarks>
        float selectionFade;

        /// <summary>
        /// Gets or sets the text of this menu entry.
        /// </summary>
        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        /// <summary>
        /// Event raised when the menu entry is selected.
        /// </summary>
        public event EventHandler<EventArgs> Selected;

        /// <summary>
        /// Method for raising the Selected event.
        /// </summary>
        protected internal virtual void OnSelectEntry(TouchLocation touch)
        {
           /* if (Selected != null)
                Selected(this, EventArgs.Empty); */
            if (EntryPosition.Contains((int)touch.Position.X, (int)touch.Position.Y))
            {
                if (touch.State == TouchLocationState.Pressed) isTouch = true;
                else if (touch.State == TouchLocationState.Released)
                {
                    isTouch = false;
                    Selected(this, EventArgs.Empty);
                }
            }
            else isTouch = false;
        }

        /// <summary>
        /// Constructs a new menu entry with the specified text.
        /// </summary>
        public MenuEntry(string text, Vector2 _position)
        {
            this.text = text;
            position = _position;

           
            isTouch = false;
        }

        /// <summary>
        /// Updates the menu entry.
        /// </summary>
       

        /// <summary>
        /// Draws the menu entry. This can be overridden to customize the appearance.
        /// </summary>
        public virtual void Draw(SpriteBatch spriteBatch, SpriteFont font)
        {
            // Draw the selected entry in yellow, otherwise white.
            Color color = isTouch ? Color.Yellow : Color.White;
            float scale = 1.0f;

           

            // Draw text, centered on the middle of each line.
          
         

            Vector2 origin = new Vector2(-1, - 1);

          
            spriteBatch.DrawString(font, text, position, Color.Black, 0,
                                   origin, scale, SpriteEffects.None, 0);
            origin = new Vector2(0, 0);

            spriteBatch.DrawString(font, text, position, color, 0,
                                   origin, scale, SpriteEffects.None, 0);
            Vector2 actualSize = font.MeasureString(text);
            EntryPosition = new Rectangle((int)position.X, (int)position.Y,
                                          (int)(actualSize.X * scale), (int)(actualSize.Y * scale));
         
        }


        

        /// <summary>
        /// Queries how much space this menu entry requires.
        /// </summary>
        
    }
}
